﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

namespace GymMaster.View
{
    public partial class WebForm1 : BasePageGymMaster
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }


        protected void lgnAcesso_Authenticate(object sender, EventArgs e)
        {
            try
            {
                String senha = lgnAcesso.Password.ToString();
                String login = lgnAcesso.UserName.ToString();

                GymMasterEntities entity = new GymMasterEntities();
                USUARIO usuario = new USUARIO();

                String dadosLogin = (from usu in entity.USUARIO
                                 where usu.USUARIO1 == login
                                 && usu.SENHA == senha
                                 && usu.ATIVO == true
                                 select usu.USUARIO1).SingleOrDefault();;

                if (dadosLogin != null)
                {
                    Session["Usuario"] = dadosLogin.ToString();
                    Response.Redirect("~/View/Administracao/Administracao.aspx");
                }
                else
                {
                    lgnAcesso.FailureText = "Usuário/Senha inválido, tente novamente.";
                }
                // APENAS PARA TESTE
                //foreach (String usuarioLogado in dadosLogin)
                //{
                //    ShowMsg(usuarioLogado);
                //}
            }
            catch (Exception)
            {

                throw;
            }
        }
    }
}
